/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 2 -*- */
/**
* @headerfile accelerometer.hpp
* 
* Header for managing the accelerometers.
* 
* @author Miguel Ángel Vílchez López 2010 <sacra@openmatica.es>
*
* Code derived from openmoko.org ( accelerometer data retrieval ).
* @sa http://wiki.openmoko.org/wiki/Accelerometer_data_retrieval
*
* Codigo is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* Codigo is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License along
* with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _MOKARDU_ACCELEROMETER_HPP_
#define _MOKARDU_ACCELEROMETER_HPP_

#include <linux/input.h>
#include "debug.hpp"

/**
* @class CMAccelerometer
* @brief Managing accelerometers.
*/

class CMAccelerometer
{

	private:
	
		/**
		* The log class.
		*/
		CMDebug debug;
		
		/**
		* The sys file for the accelerometers device.
		*/
		char* file;
				
		/**
		* The X value.
		*/
		int x;
		
		/**
		* The Y value.
		*/
		int y;
		
		/**
		* The Z value.
		*/
		int z;

		/**
		* Returns all the values of accelerometers.
		*
		* @param[in] fd The descriptor of accelerometer device.
		* @param[out] buf The result in format of input_event(struct).
		* @return The number of bytes readed, -1 if error.
		*/
		int readAll(int fd, struct input_event *buf);

	
	public:
	
		/**
		* Constructor.
		*
		* @param[in] file The file of the device.
		* @param[in] debug If the debug is activated.
		* @param[in] filename The file for logging.
		*/
		CMAccelerometer(const char* file,bool debug,const char* filename);
		
		/**
		* Destructor.
		*/
		~CMAccelerometer();

		/**
		* Get the accelerometer value.\n
		* Y(0),X(1) => MacBook\n
		* X(0),Y(1),Z(2) => OpenMoko
		*
		* @param[in] dimension Dimension value.
		* @return The accelerometer value.
		*/
		int getValue(int dimension);
		
		/**
		* Get the accelerometer value.
		*
		* @param[in] dimension Dimension value.
		* @return The accelerometer value.
		*/
		int getValue(char dimension);
	
		/**
		* Updates the acelerometer values.
		*/
		void check();
		
};
		
#endif // _MOKARDU_ACCELEROMETER_HPP_
